#pragma once

#include <pch.h>

class MuffClipperStage
{
public:
    MuffClipperStage() = default;

    void prepare (double sampleRate);
    void reset();

    template <bool highQuality>
    void processBlock (AudioBuffer<float>& buffer,
                       const chowdsp::SmoothedBufferValue<float>& clipV1Smoothed,
                       const chowdsp::SmoothedBufferValue<float>& clipV2Smoothed,
                       const chowdsp::SmoothedBufferValue<float>& gc12Smoothed) noexcept;

    static float getGC12 (float fs, float smoothing);
    static float getClipV (float clip);

private:
    chowdsp::IIRFilter<1, float> inputFilter[2];

    float fs = 48000.0f;
    float y_1[2] {}; // newton-raphson state
    float C_12_1[2] {}; // capacitor C12 state

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MuffClipperStage)
};
